<?php
	ob_end_flush();
	$call = $tag;
	
	$call = simplexml_import_dom($tag);
	Log::put('XCALL('.$GLOBALS['XCALL_LEVEL'].'): '.$this->tpl.'->'.$call->getName());
	
	

	$sxten = new XTEN($this->tpl);
	
	foreach ($call->attributes() as $k=>$v) {
		$sxten->vars[strtoupper($k)] = $v.'';
	}
		
	if ($GLOBALS['XCALL_LEVEL'] < self::$cfg->xcall_max_level) {
		$GLOBALS['XCALL_LEVEL']++;
		$code  = $sxten->getResult($call->getName());
		$GLOBALS['XCALL_LEVEL']--;
	} else Log::fatal("too much xcall recursion (xcall_max_level is ".self::$cfg->xcall_max_level.")");
	
	$newNode = $dom->createDocumentFragment();
	$newNode->appendXML($this->cdata($code));
	
	$tag->parentNode->replaceChild($newNode, $tag);
?>